Auto-Focus Method and Apparatus and Electronic Device

ABSTRACT

An auto-focus method including at a same moment, collecting a first image of a first object using a first image shooting unit, collecting a second image of the first object using a second image shooting unit, calculating M pieces of first depth information of M same feature point pairs in corresponding areas in the first image and the second image, determining whether confidence of the M pieces of first depth information is greater than a threshold, obtaining focusing depth information according to N pieces of first depth information in the IM pieces of first depth information when the confidence of the M pieces of first depth information is greater than the threshold, obtaining a target position of a first lens of the first image shooting unit according to the focusing depth information, and controlling the first lens to move to the target position.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of U.S. patent application Ser. No.15/515,311, filed on Mar. 29, 2017, which is a National Stage ofInternational Application No. PCT/CN2014/088003 filed on Sep. 30, 2014.The aforementioned patent applications are hereby incorporated byreference in their entireties.

TECHNICAL FIELD

This application relates to the field of electronic technologies, and inparticular, to an auto-focus method and apparatus, and an electronicdevice.

BACKGROUND

Auto-focus refers to controlling a distance from a lens to an imagesensor using an auto-focus algorithm such that a subject of ato-be-photographed object reaches a clearest state.

Commonly used focus algorithms may be classified into two types, activefocusing (a distance measurement method) and passive focusing (a hillclimbing method). In active focusing, a distance from a photographedsubject to a lens is measured using a method such as infrared distancemeasurement, ultrasonic distance measurement, and binocular stereoscopicvision, a lens position corresponding to an object distance iscalculated, and the lens position is adjusted to obtain an image infocus. In passive focusing, images with different focal lengths areobtained by changing focal lengths, definition and change trends of theimages are analyzed, an optimal focal length is found, to obtain animage in focus. Currently, a passive focusing solution is widely used inan electronic device such as a smartphone.

A speed of active focusing is fast, but in a specific scenario, afocusing failure rate is high. Precision of passive focusing is high,but a focusing speed is slow.

SUMMARY

Embodiments of this application provide an auto-focus method andapparatus, and an electronic device to improve focusing precision ofactive focusing.

A first aspect of this application provides an auto-focus method,including collecting a first image of a first object using a first imageshooting unit, and at a same moment, collecting a second image of thefirst object using a second image shooting unit, calculating M pieces offirst depth information of NM same feature point pairs in correspondingareas in the first image and the second image, where M is a positiveinteger, determining whether confidence of the M pieces of first depthinformation is greater than a threshold, obtaining focusing depthinformation according to N pieces of first depth information in the Mpieces of first depth information when the confidence of the M pieces offirst depth information is greater than the threshold, where N is apositive integer less than or equal to M, and obtaining a targetposition of a first lens of the first image shooting unit according tothe focusing depth information, and controlling the first lens to moveto the target position.

With reference to the first aspect, in a first possible implementationmanner of the first aspect, the corresponding areas are areascorresponding to positions of focus windows when the first image and thesecond image are collected, an area in the first image is a first area,an area in the second image is a second area, and determining whetherconfidence of the M pieces of first depth information is greater than athreshold includes determining whether a quantity of first featurepoints in the first area is greater than or equal to a first thresholdor determining whether a quantity of second feature points in the secondarea is greater than or equal to a second threshold, and determiningthat the confidence of the M pieces of first depth information is lessthan or equal to the threshold when the quantity of first feature pointsis less than the first threshold and/or the quantity of second featurepoints is less than the second threshold.

With reference to the first possible implementation manner of the firstaspect, in a second possible implementation manner of the first aspect,when the quantity of first feature points is greater than or equal tothe first threshold and the quantity of second feature points is greaterthan or equal to the second threshold, the method further includessearching, for the first feature points, the second feature points in afirst sequence for first matching feature points that match the firstfeature points, and searching the second feature points in a secondsequence for second matching feature points that match the first featurepoints, where the second sequence is reverse to the first sequence,determining a quantity of same matching feature points in the firstmatching feature points and the second matching feature points andcorresponding to a same feature point in the first feature points, anddetermining that the confidence of the M pieces of first depthinformation is less than or equal to the threshold when a proportion ofthe quantity to the quantity of first feature points is less than athird threshold, or determining that the confidence of the M pieces offirst depth information is greater than the threshold when a proportionof the quantity to the quantity of first feature points is greater thanor equal to a third threshold.

With reference to the second possible implementation manner of the firstaspect, in a third possible implementation manner of the first aspect,obtaining focusing depth information according to N pieces of firstdepth information in the M pieces of first depth information includesobtaining the focusing depth information according to depth informationcorresponding to the same feature point.

With reference to the first aspect or any one of the first possibleimplementation manner of the first aspect to the third possibleimplementation manner of the first aspect, in a fourth possibleimplementation manner of the first aspect, after controlling the firstlens to move to the target position, the method further includescontrolling a second lens of the second image shooting unit to move to athird position, determining that a check on the focusing depthinformation succeeds when a first contrast of an image obtained beforethe first lens moves to the target position and in a focus window areais less than a second contrast of an image obtained when the first lensis at the target position and in a focus window area, and a thirdcontrast of an image obtained when the second lens is at the thirdposition and in a focus window area is less than the second contrast,and performing image shooting at the target position.

With reference to the first aspect or any one of the first possibleimplementation manner of the first aspect to the third possibleimplementation manner of the first aspect, in a fifth possibleimplementation manner of the first aspect, before controlling the firstlens to move to the target position, the method further includesdetermining that a check on the focusing depth information issuccessful.

With reference to the fifth possible implementation manner of the firstaspect, in a sixth possible implementation manner of the first aspect,when a human face is detected in the focus window, the check isperformed on the focusing depth information using the following steps.Estimating an estimated distance between the human face and the firstlens according to a size of a human face frame, and determining that thecheck on the focusing depth information is successful when an absolutevalue of a difference between the estimated distance and the focusingdepth information is less than or equal to a fourth threshold.

With reference to any one of the fourth possible implementation mannerof the first aspect to the sixth possible implementation manner of thefirst aspect, in a seventh possible implementation manner of the firstaspect, when the confidence of the M pieces of first depth informationis less than or equal to the threshold or the check fails, the methodfurther includes controlling the first lens and the second lens of thesecond image shooting unit to move to new positions, collecting, at thenew positions and at a same time, a third image and a fourth image thatare of the first object respectively using the first image shooting unitand the second image shooting unit, calculating P pieces of second depthinformation of P same feature point pairs in corresponding areas in thethird image and the fourth image, where P is a positive integer,determining whether confidence of the P pieces of second depthinformation is greater than the threshold, obtaining new focusing depthinformation according to L pieces of second depth information in the Ppieces of second depth information when the confidence of the P piecesof second depth information is greater than the threshold, where L is apositive integer less than or equal to P, obtaining a new targetposition of the first lens according to the new focusing depthinformation, and controlling the first lens to move to the new targetposition.

With reference to the first aspect, any one of the first possibleimplementation manner of the first aspect to the third possibleimplementation manner of the first aspect, the fifth possibleimplementation manner of the first aspect, or the sixth possibleimplementation manner of the first aspect, in an eighth possibleimplementation manner of the first aspect, when the first lens iscontrolled to move to the target position, the method further includescontrolling a second lens of the second image shooting unit to move to aposition corresponding to the target position.

A second aspect of this application provides an auto-focus apparatus,including an acquiring unit configured to obtain a first image of afirst object and collected using a first image shooting unit, and asecond image of the first object and collected using a second imageshooting unit, where the first image and the second image are collectedat a same moment, and a processing unit configured to calculate M piecesof first depth information of M same feature point pairs incorresponding areas in the first image and the second image, where M isa positive integer, determine whether confidence of the M pieces offirst depth information is greater than a threshold, obtain focusingdepth information according to N pieces of first depth information inthe M pieces of first depth information when the confidence of the Mpieces of first depth information is greater than the threshold, where Nis a positive integer less than or equal to M, obtain a target positionof a first lens of the first image shooting unit according to thefocusing depth information, and control the first lens to move to thetarget position.

With reference to the second aspect, in a first possible implementationmanner of the second aspect, the corresponding areas correspond topositions of focus windows when the first image and the second image arecollected, an area in the first image is a first area, an area in thesecond image is a second area, and the processing unit is furtherconfigured to determine whether a quantity of first feature points inthe first area is greater than or equal to a first threshold ordetermine whether a quantity of second feature points in the second areais greater than or equal to a second threshold, and determine that theconfidence of the M pieces of first depth information is less than orequal to the threshold when the quantity of first feature points is lessthan the first threshold and/or the quantity of second feature points isless than the second threshold.

With reference to the first possible implementation manner of the secondaspect, in a second possible implementation manner of the second aspect,the processing unit is further configured to search, for the firstfeature points, the second feature points in a first sequence for firstmatching feature points that match the first feature points, and searchthe second feature points in a second sequence for second matchingfeature points that match the first feature points when the quantity offirst feature points is greater than or equal to the first threshold andthe quantity of second feature points is greater than or equal to thesecond threshold, where the second sequence is reverse to the firstsequence, determine a quantity of same matching feature points in thefirst matching feature points and the second matching feature points andcorresponding to a same feature point in the first feature points, anddetermine that the confidence of the M pieces of first depth informationis less than or equal to the threshold when a proportion of the quantityto the quantity of first feature points is less than a third threshold,or determine that the confidence of the M pieces of first depthinformation is greater than the threshold when a proportion of thequantity to the quantity of first feature points is greater than orequal to a third threshold.

With reference to the second possible implementation manner of thesecond aspect, in a third possible implementation manner of the secondaspect, the processing unit is further configured to obtain the focusingdepth information according to depth information corresponding to thesame feature point.

With reference to the second aspect or any one of the first possibleimplementation manner of the second aspect to the third possibleimplementation manner of the second aspect, in a fourth possibleimplementation manner of the second aspect, the processing unit isfurther configured to control a second lens of the second image shootingunit to move to a third position after controlling the first lens tomove to the target position, determine that a check on the focusingdepth information succeeds when a first contrast of an image obtainedbefore the first lens moves to the target position and in a focus windowarea is less than a second contrast of an image obtained when the firstlens is at the target position, and a third contrast of an imageobtained when the second lens is at the third position and in a focuswindow area is less than the second contrast, and control performingimage shooting at the target position.

With reference to the second aspect or any one of the first possibleimplementation manner of the second aspect to the third possibleimplementation manner of the second aspect, in a fifth possibleimplementation manner of the second aspect, the processing unit isfurther configured to determine that a check on the focusing depthinformation is successful before controlling the first lens to move tothe target position.

With reference to the fifth possible implementation manner of the secondaspect, in a sixth possible implementation manner of the second aspect,the processing unit is further configured to estimate an estimateddistance between a human face and the first lens according to a size ofa human face frame when the human face is detected in the focus window,and determine that the check on the focusing depth information issuccessful when an absolute value of a difference between the estimateddistance and the focusing depth information is less than or equal to afourth threshold.

With reference to any one of the fourth possible implementation mannerof the second aspect to the sixth possible implementation manner of thesecond aspect, in a seventh possible implementation manner of the secondaspect, the processing unit is further configured to control the firstlens and the second lens of the second image shooting unit to move tonew positions when the confidence of the M pieces of first depthinformation is less than or equal to the threshold or the check fails.The acquiring unit is further configured to obtain, at the newpositions, a third image and a fourth image that are of the first objectand collected at a same time respectively using the first image shootingunit and the second image shooting unit, and the processing unit isfurther configured to calculate P pieces of second depth information ofN same feature point pairs in corresponding areas in the third image andthe fourth image, where P is a positive integer, determine whetherconfidence of the P pieces of second depth information is greater thanthe threshold, obtain new focusing depth information according to Lpieces of second depth information in the P pieces of second depthinformation when the confidence of the P pieces of second depthinformation is greater than the threshold, where L is a positive integerless than or equal to P, obtain a new target position of the first lensaccording to the new focusing depth information, and control the firstlens to move to the new target position.

With reference to the second aspect, any one of the first possibleimplementation manner of the second aspect to the third possibleimplementation manner of the second aspect, the fifth possibleimplementation manner of the second aspect, or the sixth possibleimplementation manner of the second aspect, in an eighth possibleimplementation manner of the second aspect, the processing unit isfurther configured to control a second lens of the second image shootingunit to move to a position corresponding to the target position whencontrolling the first lens to move to the target position.

A third aspect of this application provides an electronic device,including a first image shooting unit and a second image shooting unitconfigured to respectively collect, at a same moment, a first image anda second image that are of a first object, a first actuator, and aprocessor configured to calculate M pieces of first depth information ofM same feature point pairs in corresponding areas in the first image andthe second image, where M is a positive integer, determine whetherconfidence of the M pieces of first depth information is greater than athreshold, obtain focusing depth information according to N pieces offirst depth information in the M pieces of first depth information whenthe confidence of the M pieces of first depth information is greaterthan the threshold, where N is a positive integer less than or equal toM, obtain a target position of a first lens of the first image shootingunit according to the focusing depth information, and control the firstactuator to move such that the first lens moves to the target position.

With reference to the third aspect, in a first possible implementationmanner of the third aspect, the corresponding areas correspond topositions of focus windows when the first image and the second image arecollected, an area in the first image is a first area. an area in thesecond image is a second area, and the processor is further configuredto determine whether a quantity of first feature points in the firstarea is greater than or equal to a first threshold or determine whethera quantity of second feature points in the second area is greater thanor equal to a second threshold, and determine that the confidence of theM pieces of first depth information is less than or equal to thethreshold when the quantity of first feature points is less than thefirst threshold and/or the quantity of second feature points is lessthan the second threshold.

With reference to the first possible implementation manner of the thirdaspect, in a second possible implementation manner of the third aspect,the processor is further configured to search, for the first featurepoints, the second feature points in a first sequence for first matchingfeature points that match the first feature points, and search thesecond feature points in a second sequence for second matching featurepoints that match the first feature points when the quantity of firstfeature points is greater than or equal to the first threshold and thequantity of second feature points is greater than or equal to the secondthreshold, where the second sequence is reverse to the first sequence,determine a quantity of same matching feature points in the firstmatching feature points and the second matching feature points andcorresponding to a same feature point in the first feature points, anddetermine that the confidence of the M pieces of first depth informationis less than or equal to the threshold when a proportion of the quantityto the quantity of first feature points is less than a third threshold,or determine that the confidence of the M pieces of first depthinformation is greater than the threshold when a proportion of thequantity to the quantity of first feature points is greater than orequal to a third threshold.

With reference to the second possible implementation manner of the thirdaspect, in a third possible implementation manner of the third aspect,the processor is further configured to obtain the focusing depthinformation according to depth information corresponding to the samefeature point.

With reference to the third aspect or any one of the first possibleimplementation manner of the third aspect to the third possibleimplementation manner of the third aspect, in a fourth possibleimplementation manner of the third aspect, the electronic device furtherincludes a second actuator, and the processor is further configured tocontrol the second actuator to move in order to move a second lens ofthe second image shooting unit to a third position after controlling thefirst lens to move to the target position, determine that a check on thefocusing depth information succeeds when a first contrast of an imageobtained before the first lens moves to the target position and in afocus window area is less than a second contrast of an image obtainedwhen the first lens is at the target position and in a focus windowarea, and a third contrast of an image obtained when the second lens isat the third position and in a focus window area is less than the secondcontrast, and control performing image shooting at the target position.

With reference to the third aspect or any one of the first possibleimplementation manner of the third aspect to the third possibleimplementation manner of the third aspect, in a fifth possibleimplementation manner of the third aspect, the processor is furtherconfigured to determine that a check on the focusing depth informationis successful before controlling the first lens to move to the targetposition.

With reference to the fifth possible implementation manner of the thirdaspect, in a sixth possible implementation manner of the third aspect,the processor is further configured to estimate an estimated distancebetween a human face and the first lens according to a size of a humanface frame when the human face is detected in the focus window, anddetermine that the check on the focusing depth information is successfulwhen an absolute value of a difference between the estimated distanceand the focusing depth information is less than or equal to a fourththreshold.

With reference to any one of the fourth possible implementation mannerof the third aspect to the sixth possible implementation manner of thethird aspect, in a seventh possible implementation manner of the thirdaspect, the processor is further configured to control the first lensand the second lens of the second image shooting unit to move to newpositions when the confidence of the M pieces of first depth informationis less than or equal to the threshold or the check fails, and at thenew positions, a third image and a fourth image that are of the firstobject and collected at a same time using the first image shooting unitand the second image shooting unit, and the processor is furtherconfigured to calculate P pieces of second depth information of N samefeature point pairs in corresponding areas in the third image and thefourth image, where P is a positive integer, determine whetherconfidence of the P pieces of second depth information is greater thanthe threshold, obtain new focusing depth information according to Lpieces of second depth information in the P pieces of second depthinformation when the confidence of the P pieces of second depthinformation is greater than the threshold, where L is a positive integerless than or equal to P, obtain a new target position of the first lensaccording to the new focusing depth information, and control the firstlens to move to the new target position.

With reference to the third aspect, any one of the first possibleimplementation manner of the third aspect to the third possibleimplementation manner of the third aspect, the fifth possibleimplementation manner of the third aspect, or the sixth possibleimplementation manner of the third aspect, in an eighth possibleimplementation manner of the third aspect, the processor is furtherconfigured to control a second lens of the second image shooting unit tomove to a position corresponding to the target position when controllingthe first lens to move to the target position.

One or more technical solutions provided in the embodiments of thisapplication have at least the following technical effects or advantages.

In the embodiments of this application, at a same moment, a first imageof a first object is collected using a first image shooting unit, and asecond image of the first object is collected using a second imageshooting unit, M pieces of first depth information of M same featurepoint pairs in corresponding areas in the first image and the secondimage are calculated, it is determined whether confidence of the Mpieces of first depth information is greater than a threshold, focusingdepth information is obtained according to N pieces of first depthinformation in the M pieces of first depth information when theconfidence of the M pieces of first depth information is greater thanthe threshold. Then, a target position of a first lens is obtainedaccording to the focusing depth information, and the first lens iscontrolled to move to the target position. Therefore, in theembodiments, confidence of an object distance obtained in activefocusing, that is, the M pieces of first depth information isdetermined. An active focusing method is used only when the confidenceis greater than the threshold, that is, focusing depth information isobtained according to N pieces of first depth information in the Mpieces of first depth information. Then, the target position of thefirst lens is obtained according to the focusing depth information, andthen the first lens is controlled to move to the target position tocomplete focusing. Therefore, in comparison with an active focusingmethod in the prior art, focusing precision is improved.

BRIEF DESCRIPTION OF DRAWINGS

FIG. 1 is a flowchart of an auto-focus method according to an embodimentof this application;

FIG. 2 is a schematic disposing diagram of a lens of an image shootingunit according to an embodiment of this application;

FIG. 3 is an example flowchart diagram of an auto-focus method accordingto an embodiment of this application;

FIG. 4 is a functional block diagram of an auto-focus apparatusaccording to an embodiment of this application; and

FIG. 5 is a system block diagram of an electronic device according to anembodiment of this application.

DESCRIPTION OF EMBODIMENTS

Embodiments of this application provide an auto-focus method andapparatus, and an electronic device to improve focusing precision ofactive focusing.

To make the objectives, technical solutions, and advantages of theembodiments of this application clearer, the following clearly describesthe technical solutions in the embodiments of this application withreference to the accompanying drawings in the embodiments of thisapplication. The described embodiments are merely some but not all ofthe embodiments of this application. All other embodiments obtained bypersons of ordinary skill in the art based on the embodiments of thisapplication without creative efforts shall fall within the protectionscope of this application.

First, an implementation process of an auto-focus method in anembodiment of this application is described. Referring to FIG. 1, FIG. 1is a flowchart of the auto-focus method in this embodiment, and themethod includes the following content.

Step 101: At a same moment, collect a first image of a first objectusing a first image shooting unit (e.g. a first camera), and collect asecond image of the first object using a second image shooting unit(e.g. a second camera).

Optionally, parameters of the first image shooting unit and the secondimage shooting unit are the same. For example, the first image shootingunit and the second image shooting unit may also have a same focallength and same image sensors. Certainly, the first image shooting unitand the second image shooting unit may also have same lenses and anothersame hardware parameter.

It should be noted that, that the first image shooting unit and thesecond image shooting unit have one same parameter may be understood asthat parameters of the first image shooting unit and the second imageshooting unit are the same. Certainly, that the first image shootingunit and the second image shooting unit have multiple same parameters(for example, two or three same parameters) may also be understood asthat parameters of the first image shooting unit and the second imageshooting unit are the same. Preferably, all parameters of the firstimage shooting unit and the second image shooting unit are the same,that is, the first image shooting unit and the second image shootingunit are two same image shooting units.

The first image shooting unit and the second image shooting unit aredisposed on an electronic device. For example, the electronic device isa mobile phone, a tablet computer, or a camera.

Optionally, a first lens of the first image shooting unit and a secondlens of the second image shooting unit are disposed on a same side ofthe electronic device. Preferably, the first lens and the second lensare disposed on a same plane of the electronic device. For example, bothof them are disposed on a rear cover of a mobile phone.

Optionally, the first lens may be a front-facing lens, and the secondlens is a rear-facing lens. In use, one of the lenses may be flipped toa same side as the other lens.

Preferably, when an image is being obtained, an optical axis of thefirst image shooting unit is parallel to an optical axis of the secondimage shooting unit, to ensure that motion between the collected firstimage and second image is translation motion. In this way, a correctioncomputation amount is small.

Referring to FIG. 2, FIG. 2 is a possible schematic diagram when a firstimage shooting unit 201 and a second image shooting unit 202 aredisposed on an electronic device 20. The first image shooting unit 201and the second image shooting unit 202 are disposed on a same side ofthe electronic device 20. For example, the first image shooting unit 201and the second image shooting unit 202 are disposed on a rear cover sideof the electronic device 20.

When the electronic device 20 is held in hand to take a photo, a firstimage is photographed using the first image shooting unit 201, and asecond image is photographed at a same time using the second imageshooting unit 202. Although the first image shooting unit 201 and thesecond image shooting unit 202 perform photographing on a same object,that is, a first object, a first collection area of the first imageshooting unit 201 and a second collection area of the second imageshooting unit 202 are not completely the same because there is adistance between an optical axis of the first image shooting unit 201and that of the second image shooting unit 202 in a horizontaldirection. However, there is an overlapped collection area between thefirst collection area and the second collection area.

Optionally, the electronic device 20 that photographs the first imageand the second image and an electronic device that performs steps 102and 103 may be a same electronic device. Further, the electronic device20 obtains image signals using image sensors such as a charge-coupleddevice (CCD) or a complementary metal oxide semiconductor (CMOS) in thefirst image shooting unit 201 and the second image shooting unit 202,and then transmits these image signals to an image signal processor(ISP). The ISP preprocesses the image signals to obtain the first imageand the second image.

Optionally, the electronic device 20 that photographs the first imageand the second image may not be a same electronic device as anelectronic device that performs steps 102 and 103. For example, theelectronic device 20 that photographs the first image and the secondimage is a mobile phone, a tablet computer, or a single-lens reflexcamera, and a photographing process is described as above. Theelectronic device that performs the step 102 is a notebook computer,another mobile phone, or another tablet computer. In this case, afterthe first image and the second image are obtained by means ofphotographing, the first image and the second image are transmitted tothe notebook computer, the other mobile phone, or the other tabletcomputer, and therefore, the notebook computer, the other mobile phone,or the other tablet computer obtains the first image and the secondimage.

Step 102: Calculate M pieces of first depth information of M samefeature point pairs in corresponding areas in the first image and thesecond image, where M is a positive integer and is less than or equal toa smaller total quantity of pixels in a total quantity of pixels in thefirst image and a total quantity of pixels in the second image. Forexample, M is less than or equal to 600×900 if the total quantity ofpixels in the first image is 600×1200 and the total quantity of pixelsin the second image is 600×900.

In this technical field, depth information indicates a distance betweena photographed object and a lens. In this embodiment of thisapplication, the M pieces of first depth information indicate distancesseparately between the first lens and M positions on the first objectcorresponding to the feature points.

In this technical field, a feature point is a pixel having a specificfeature in an image, and an image feature has a color feature, a texturefeature, a shape feature, and a spatial relationship feature. Featurepoints extracted according to different feature point extraction methodshave different features. For example, a corner point (that is, a featurepoint) extracted using a Harris corner point extraction method is apoint at which brightness of a two-dimensional image changesdramatically or a point corresponding to a maximum curvature value on animage edge curve. For another example, a feature point extracted using afeature extraction method of scale-invariant feature transform (SIFT) isa feature vector irrelevant to scale zooming, rotation, and brightnessvariation. In this embodiment of this application, feature pointextraction and calculating depth information of a feature pointaccording to parallax between same feature points are content well knownand details are not described herein again.

Optionally, the corresponding areas correspond to positions of focuswindows when the first image and the second image are collected. It isassumed that an area in the first image is a first area, and an area inthe second image is a second area. Because focusing needs to beperformed, accuracy is relatively high and a calculation amount is smallwhen a manner of calculating depth information of the positions of thefocus windows is selected. Certainly, in practical application, thecorresponding area may also be another area, or may even be an entireimage area, which is not limited in this application.

Optionally, first feature points in the first area and second featurepoints in the second area may be extracted, and then depth informationof the feature points, that is, the M pieces of first depth information,may be calculated according to parallax between same feature points inthe first feature points and the second feature points.

After the M pieces of first depth information are calculated, step 103is performed subsequently.

Step 103: Determine whether confidence of the M pieces of first depthinformation is greater than a threshold.

The confidence represents reliability or precision of depth information.

In an embodiment, determining whether confidence of the M pieces offirst depth information is greater than a threshold may be implementedin the following manner. Determining whether a quantity of first featurepoints is greater than or equal to a first threshold or determiningwhether a quantity of second feature points is greater than or equal toa second threshold, and when the quantity of first feature points isless than the first threshold and/or the quantity of second featurepoints is less than the second threshold, determining that theconfidence of the M pieces of first depth information is less than orequal to the threshold. It is assumed that there are totally 100 pixelsin the first area, but when a quantity of feature points extractedaccording to a specific feature point extraction method is less than thethreshold (for example, the threshold is 30), for example, there areonly two feature points, confidence of depth information calculatedaccording to 50 feature points is greater than confidence of depthinformation calculated according to two feature points. Therefore,confidence of depth information calculated according to the firstfeature points and the second feature points is relatively low when thequantity of first feature points is less than the first threshold or thequantity of second feature points is less than the second threshold.

Further, there are the following three cases. In the first case, it isdetermined whether the quantity of first feature points is greater thanor equal to the first threshold, it is determined that the confidence ofthe M pieces of first depth information is less than or equal to thethreshold if the quantity of first feature points is less than the firstthreshold.

In the second case, it is determined whether the quantity of secondfeature points is greater than or equal to the second threshold, it isdetermined that the confidence of the M pieces of first depthinformation is less than or equal to the threshold if the quantity ofsecond feature points is less than the second threshold.

In the third case, it may be determined that the confidence of the Mpieces of first depth information is less than or equal to the thresholdprovided that the quantity of first feature points is less than thefirst threshold or the quantity of second feature points is less thanthe second threshold.

Correspondingly, in the first case, when the quantity of first featurepoints is greater than the first threshold, it may be determined thatthe confidence of the M pieces of first depth information is greaterthan the threshold. Optionally, to further confirm that the confidenceof the M pieces of first depth information is greater than thethreshold, the method further includes searching, for the first featurepoints, the second feature points in a first sequence for first matchingfeature points that match the first feature points, and searching thesecond feature points in a second sequence for second matching featurepoints that match the first feature points, where the first sequence isreverse to the second sequence, determining a quantity of same matchingfeature points that are in the first matching feature points and thesecond matching feature points and that are corresponding to a samefeature point in the first feature points, where each pair of samematching feature points corresponds to a same feature point in the firstfeature points, and determining that the confidence of the M pieces offirst depth information is less than or equal to the threshold when aproportion of the quantity to the quantity of first feature points isless than a third threshold, or determining that the confidence of the Mpieces of first depth information is greater than the threshold when aproportion of the quantity to the quantity of first feature points isgreater than or equal to a third threshold.

Further, the first sequence is a sequence from left to right, and thesecond sequence is a sequence from right to left. In practicalapplication, the first sequence may also be a sequence from top tobottom, and the second sequence is a sequence from bottom to top.

For example, the first feature points are successively A, B, C, and Dfrom left to right, and the second feature points are successively a, b,c, and d from left to right. For the first feature points, first, thesecond feature points are searched in a sequence from left to right forthe first matching feature points that match the first feature points.It is assumed that a result of searching the second feature point bmatches the first feature point B. The first matching feature point isthe second feature point b. Then, the second feature points are searchedin a sequence from right to left for the second matching feature pointsthat match the first feature points. It is assumed that a result ofsearching the second feature point b matches the first feature point B,and the second feature point c matches the first feature point C. Thesecond matching feature points are the second feature point b and thesecond feature point c. It may be seen that the first feature point Bmatches the second feature point b in both two times of searching, andtherefore, the first feature point 13 is a feature point with highconfidence, and is referred to as a first sub feature point. In otherwords, the quantity of same matching feature points in the firstmatching feature points and the second matching feature points isdetermined, where each pair of same matching feature points correspondsto a same feature point in the first feature points. The quantity ofsame matching feature points is also a quantity of first sub featurepoints.

It is determined that the confidence of the M pieces of first depthinformation is less than or equal to the threshold when the proportionof the quantity to the quantity of first feature points is less than thethird threshold.

It is determined that the confidence of the MN pieces of first depthinformation is greater than the threshold when the proportion of thequantity to the quantity of first feature points is greater than orequal to the third threshold.

In other words, in this embodiment of this application, when featurepoint matching can succeed in both of two directions and a quantity offeature point pairs that match successfully is larger, it means thatthere are more reliable feature points, and confidence of depthinformation calculated using the feature points is higher. If a quantityof feature pairs that match successfully in both of the two directionsis smaller, it means that there are fewer reliable feature points, andconfidence of depth information calculated using the feature points islower.

Corresponding to the foregoing second case, it may be determined thatthe confidence of the M pieces of first depth information is greaterthan the threshold when the quantity of second feature points is greaterthan the first threshold. Optionally, to further confirm that theconfidence of the M pieces of first depth information is greater thanthe threshold, steps same as the foregoing may be performed.

Corresponding to the foregoing third case, the foregoing described stepof further confirming that the confidence of the M pieces of first depthinformation is greater than the threshold is performed when the quantityof first feature points is greater than or equal to the first thresholdand when the quantity of second feature points is greater than or equalto the second threshold.

When it is determined, using the foregoing methods, that the confidenceof the M pieces of first depth information is greater than thethreshold, a step 104 is performed subsequently.

Step 104: Obtain focusing depth information according to N pieces offirst depth information in the MN pieces of first depth information whenthe confidence of the M pieces of first depth information is greaterthan the threshold, where N is a positive integer less than or equal toM.

In an embodiment, obtaining the focusing depth information according toN pieces of first depth information in the M pieces of first depthinformation may have multiple implementation manners. Further, in thefirst implementation manner, a weighted average value of the M pieces offirst depth information is used as the focusing depth information. Inthe second implementation manner, depth information that issignificantly different from other depth information may be firstexcluded from the M pieces of first depth information, and then aweighted average value of remaining first depth information iscalculated and used as the focusing depth information. In the thirdimplementation manner, one piece of first depth information is selectedfrom the M pieces of first depth information as the focusing depthinformation. In the fourth implementation manner, multiple pieces offirst depth information are randomly selected from the M pieces of firstdepth information, and then weighted average calculation is performed toobtain the focusing depth information.

In another embodiment, when the foregoing described method of furtherconfirming whether the confidence of the M pieces of first depthinformation is greater than the threshold is implemented, obtaining thefocusing depth information according to N pieces of first depthinformation in the M pieces of first depth information includesobtaining the focusing depth information according to depth informationcorresponding to the same feature point, that is, the first sub featurepoint. Further, in an embodiment, the focusing depth information is aweighted average value of depth information of all first sub featurepoints. In another embodiment, a first sub feature point of which depthinformation is significantly different from a majority of depthinformation is first excluded, and a weighted average of depthinformation of remaining first sub feature points is calculated and usedas the final focusing depth information. Because the first sub featurepoint is a feature point with high confidence obtained by means ofscreening using the foregoing method, accuracy of the focusing depthinformation calculated according to the depth information correspondingto the first sub feature point is higher.

Step 105: Obtain a target position of a first lens of the first imageshooting unit according to the focusing depth information, and controlthe first lens to move to the target position. Further, the obtaining atarget position of a first lens according to the focusing depthinformation may also have multiple implementation manners. For example,if a correspondence between an object distance and a position of thefirst lens is stored in an electronic device, the target positioncorresponding to the focusing depth information may be obtained byquerying the correspondence. For another example, obtaining the focusingdepth information is equivalent to obtaining an object distance, andtherefore, a focal length may be calculated according to the objectdistance, and further the target position may be obtained.

Optionally, the controlling the first lens to move to the targetposition may be controlling movement of the first lens by controlling afirst actuator, for example, a voice coil motor (VCM). Further, the VCMincludes a coil, a magnet set, and a spring plate. The coil is fixed inthe magnet set using two spring plates, an upper spring plate and alower spring plate. The coil generates a magnetic field when the coil ispowered on. The magnetic field of the coil interacts with the magnetset, the coil moves upward, and the first lens locked in the coil movestogether. The coil returns back to an original position under an elasticforce of the spring plate when the coil is powered off.

Certainly, in practical application, further, the first lens may furtherbe drove, by controlling another actuator such as a motor in anotherform or an associated component, to move to the target position.

Step 105 is similar to active focusing, that is, when the confidence ofthe M pieces of first depth information is greater than the threshold,the active focusing may be used, which improves focusing precision in acase of ensuring a focusing speed.

Optionally, when the first lens is controlled to move to the targetposition, the method further includes controlling a second lens of thesecond image shooting unit to move to a position corresponding to thetarget position.

Further, the position to which the second lens needs to move may also befurther determined in multiple manners. In the first manner, forexample, a correspondence between the object distance and a position ofthe second lens may further be included in the correspondence of theobject distance and the position of the first lens. The position towhich the second lens needs to move may be obtained by querying thecorrespondence. In this embodiment, the positions to which the firstlens and the second lens need to move may be determined using the targetposition or the focusing depth information.

In the second manner, the second lens may also be moved to acorresponding position using steps similar to the steps 102 to 105. Inthis embodiment, processing is separately performed for the two lenses,and processing methods are the same.

Optionally, further, after the first lens moves to the target position,a user may press a shutter to shoot an image. Because focusing isperformed, definition of an image area corresponding to the focus windowis higher than that of another area. For the second image shooting unit,a principle is the same. After the second lens moves to the positioncorresponding to the target position, a focused image may also beobtained.

Optionally, after the focusing depth information is obtained, a checkmay further be performed on the focusing depth information. Imageshooting is performed at the target position only after the checksucceeds. Steps of the check include controlling the second lens of thesecond image shooting unit to move to a third position, and determiningthat the check on the focusing depth information succeeds when a firstcontrast of an image obtained before the first lens moves to the targetposition and in a focus window area is less than a second contrast of animage obtained when the first lens is at the target position and in afocus window area, and a third contrast of an image obtained when thesecond lens is at the third position and in a focus window area is lessthan the second contrast.

An image contrast refers to an image color difference. In practicalapplication, there are different calculation methods, for example,measurement of different brightness levels between the brightest whitearea and the darkest black area in an image in a focus window area, alarger difference range represents a larger contrast, and a smallerdifference range represents a smaller contrast. Contrast calculation iscontent well known by persons skilled in the art. Therefore, details arenot described herein again.

For example, it is assumed that a position of the first lens before thefirst lens moves to the target position is P0, and the target positionis P1. It is assumed that the third position is P2, and in anembodiment, P2=(P0+P1)/2. It is assumed that at the position P0, acontrast of an image obtained by the first image shooting unit and is inthe focus window area is a first contrast C(P0). A contrast of an imageobtained at the position P1 by the first image shooting unit and is inthe focus window area is a second contrast C(P1). A contrast of an imageobtained at the position P2 by the second image shooting unit and is inthe focus window area is a third contrast C(P2). It is determined thatthe check on the focusing depth information succeeds when C(P2)<C(P1)and C(P0)<C(P1). It is determined that the check on the focusing depthinformation fails when C(P2) is greater than or equal to C(P1), or C(P0)is greater than or equal to C(P1).

Optionally, before the first lens is controlled to move to the targetposition, it may be determined that the check on the focusing depthinformation is successful. In this embodiment, steps of the check on thefocusing depth information include calculating an estimated size of thefirst object according to a size of the first object in the first image,comparing the estimated size obtained through calculation with priordata, where if an absolute value of a difference between the estimatedsize and the prior data is greater than a set threshold, it indicatesthat the check on the focusing depth information fails, and otherwise,the check succeeds. The estimated size of the first object is calculatedaccording to the size of the first object in the first image, and may befurther calculated in the following way. Because the size of the firstobject in the first image, a distance between the image sensor and thefirst lens, and the M pieces of first depth information are all known,the estimated size of the first object may be obtained throughcalculation according to an imaging principle and a similar triangleprinciple. For example, it is assumed that a width of a car is 3 meters,but an estimated size of the car calculated according to a size of thecar in the first image is much greater than 3 meters, it means thatcalculation of the M pieces of first depth information is wrong, and itindicates that the check fails, and otherwise, the check succeeds.

In a scenario of photographing a person, when a human face is detectedin the focus window, in addition to the foregoing check methods, thecheck may further be performed on the focusing depth information usingthe following steps. Estimating an estimated distance between the humanface and the first lens according to a size of a human face frame, anddetermining that the check on the focusing depth information issuccessful when an absolute value of a difference between the estimateddistance and the focusing depth information is less than or equal to afourth threshold. Otherwise, the check on the focusing depth informationfails. The human face frame represents a position of the human face.

The estimating an estimated distance between the human face and thefirst lens according to a size of a human face frame is as follows. Aquantity of pixels corresponding to the human face frame, that is, asize in the first image, is in a specific proportion to a distancebetween the human face and the first lens, and then the estimateddistance between the human face and the first lens may be estimatedaccording to the proportion and the size of the human face frame. Then,when an absolute value of a difference between the focusing depthinformation and the estimated distance estimated using this method isless than or equal to the fourth threshold, it means that the checksucceeds, and otherwise, the check fails.

Optionally, when the check succeeds, distance measurement methodfocusing is enabled according to the focusing depth information todirectly move the lens to a position of a corresponding depth.

Optionally, regardless of using which of the foregoing check methods oranother check method, when the check fails, or the confidence of the Mpieces of first depth information is less than or equal to thethreshold, the method further includes controlling the first lens andthe second lens of the second image shooting unit to move to newpositions, collecting, at the new positions and at a same time, a thirdimage and a fourth image that are of the first object respectively usingthe first image shooting unit and the second image shooting unit,calculating P pieces of second depth information of P same feature pointpairs in corresponding areas in the third image and the fourth image,determining whether confidence of the P pieces of second depthinformation is greater than the threshold, obtaining new focusing depthinformation according to L second depth information in the P pieces ofsecond depth information when the confidence of the P pieces of seconddepth information is greater than the threshold, obtaining a new targetposition of the first lens according to the new focusing depthinformation, and controlling the first lens to move to the new targetposition, where P is a positive integer, and L is a positive integerless than or equal to M. Certainly, P is less than or equal to a smallertotal quantity of pixels in a total quantity of pixels in the thirdimage and a total quantity of pixels in the fourth image.

Optionally, the first lens and the second lens are moved to the newpositions and may be moved in a fixed step length manner, that is,moving amplitude each time is the same. A manner of gradually increasingor gradually decreasing a moving step length may also be used to movethe lenses. In practical application, moving may further be performedaccording to another rule, which is not limited in this application.

An implementation process of remaining steps is similar to that of theforegoing steps represented in FIG. 1, and details are not describedherein again.

In this embodiment, it is equivalent to that after a lens is moved eachtime in passive focusing, depth information is recalculated, and thenconfidence of the depth information is determined, where when theconfidence is high, a manner similar to active focusing is used or acheck is performed on the distance. If the confidence is low or thechecking fails, the lens is moved again, depth information isrecalculated again, and then confidence of the depth information isdetermined again. This cycle is repeated in this way. Both a speed ofactive focusing and precision of passive focusing may be ensured usingthe method in this embodiment.

The following describes a specific example of an auto-focus method, andreference may be made to FIG. 3.

First, a first image and a second image are obtained, and further,position information of focus windows when the first image and thesecond image are photographed is further obtained. Then, M pieces offirst depth information of M same feature point pairs in correspondingareas in the first image and the second image are calculated. Further,depth information of same feature points in focus window areas may becalculated and used as the M pieces of first depth information. Then, itis determined whether confidence of the M pieces of first depthinformation is greater than a threshold. Passive focusing is enabled ifthe confidence of the M pieces of first depth information is not greaterthan the threshold. If the confidence of the M pieces of first depthinformation is greater than the threshold, focusing depth information isobtained according to N pieces of first depth information in the Mpieces of first depth information, and a check is performed on thefocusing depth information. Then, it is determined whether the checksucceeds. If the check fails, the passive focusing is also enabled. Ifthe check succeeds, active focusing is enabled. Optionally, after thepassive focusing is enabled, and a lens is moved to a new position, goback and continue to perform a step of calculating the M pieces of firstdepth information, and then continue to perform steps subsequently in asequence of the flowchart. This cycle is repeated in this way untilfocusing succeeds.

Based on a same inventive concept, an embodiment of this applicationfurther provides an auto-focus apparatus. Referring to FIG. 4, FIG. 4 isa functional block diagram of the auto-focus apparatus. A term involvedin this embodiment is the same as or similar to the foregoing term. Theapparatus includes an acquiring unit 301 configured to obtain a firstimage of a first object and collected using a first image shooting unit,and a second image of the first object and collected using a secondimage shooting unit, where the first image and the second image arecollected at a same moment, and a processing unit 302 configured tocalculate M pieces of first depth information of M same feature pointpairs in corresponding areas in the first image and the second image,where M is a positive integer, determine whether confidence of the Mpieces of first depth information is greater than a threshold, obtainfocusing depth information according to N pieces of first depthinformation in the M pieces of first depth information when theconfidence of the M pieces of first depth information is greater thanthe threshold, where N is a positive integer less than or equal to M,and obtain a target position of a first lens of the first image shootingunit according to the focusing depth information, and control the firstlens to move to the target position.

Optionally, the corresponding areas correspond to positions of focuswindows when the first image and the second image are collected, an areain the first image is a first area, an area in the second image is asecond area, and the processing unit 302 is further configured todetermine whether a quantity of first feature points in the first areais greater than or equal to a first threshold or determine whether aquantity of second feature points in the second area is greater than orequal to a second threshold, and determine that the confidence of the Mpieces of first depth information is less than or equal to the thresholdwhen the quantity of first feature points is less than the firstthreshold and/or the quantity of second feature points is less than thesecond threshold.

The processing unit 302 is further configured to search, for the firstfeature points, the second feature points in a first sequence for firstmatching feature points that match the first feature points, and searchthe second feature points in a second sequence for second matchingfeature points that match the first feature points when the quantity offirst feature points is greater than or equal to the first threshold andthe quantity of second feature points is greater than or equal to thesecond threshold, where the second sequence is reverse to the firstsequence, determine a quantity of same matching feature points that arein the first matching feature points and the second matching featurepoints and corresponding to a same feature point in the first featurepoints, and determine that the confidence of the M pieces of first depthinformation is less than or equal to the threshold when a proportion ofthe quantity to the quantity of first feature points is less than athird threshold, or determine that the confidence of the M pieces offirst depth information is greater than the threshold when a proportionof the quantity to the quantity of first feature points is greater thanor equal to a third threshold.

The processing unit 302 is further configured to obtain the focusingdepth information according to depth information corresponding to thesame feature point.

With reference to the foregoing embodiments, the processing unit 302 isfurther configured to control a second lens of the second image shootingunit to move to a third position after controlling the first lens tomove to the target position, determine that a check on the focusingdepth information succeeds when a first contrast of an image obtainedbefore the first lens moves to the target position and in a focus windowarea is less than a second contrast of an image obtained when the firstlens is at the target position and in a focus window area, and a thirdcontrast of an image obtained when the second lens is at the thirdposition and in a focus window area is less than the second contrast,and control performing image shooting at the target position.

With reference to the foregoing embodiments, the processing unit 302 isfurther configured to determine that a check on the focusing depthinformation is successful before controlling the first lens to move tothe target position.

The processing unit 302 is further configured to estimate an estimateddistance between a human face and the first lens according to a size ofa human face frame when the human face is detected in the focus window,and determine that the check on the focusing depth information issuccessful when an absolute value of a difference between the estimateddistance and the focusing depth information is less than or equal to afourth threshold.

With reference to the foregoing embodiments, the processing unit 302 isfurther configured to control the first lens and the second lens of thesecond image shooting unit to move to new positions when the confidenceof the M pieces of first depth information is less than or equal to thethreshold or the check fails.

The acquiring unit 301 is further configured to obtain, at the newpositions, a third image and a fourth image of the first object andcollected at a same time respectively using the first image shootingunit and the second image shooting unit.

The processing unit 302 is further configured to calculate P pieces ofsecond depth information of N same feature point pairs in correspondingareas in the third image and the fourth image, where P is a positiveinteger, determine whether confidence of the P pieces of second depthinformation is greater than the threshold, obtain new focusing depthinformation according to L pieces of second depth information in the Ppieces of second depth information when the confidence of the P piecesof second depth information is greater than the threshold, where L is apositive integer less than or equal to P, obtain a new target positionof the first lens according to the new focusing depth information, andcontrol the first lens to move to the new target position.

With reference to the foregoing embodiments, the processing unit 302 isfurther configured to control a second lens of the second image shootingunit to move to a position corresponding to the target position whencontrolling the first lens to move to the target position.

Various types of variations and specific examples in the auto-focusmethod in the foregoing embodiments in FIG. 1 to FIG. 3 are alsoapplicable to the auto-focus apparatus in this embodiment. With thedetailed description of the foregoing auto-focus method, persons skilledin the art may clearly understand an implementation method of theauto-focus apparatus in this embodiment. Therefore, for conciseness ofthe specification, details are not described herein again.

Based on a same inventive concept, an embodiment of this applicationfurther provides an electronic device. Referring to FIG. 5, FIG. 5 is asystem block diagram of the electronic device in this embodiment. A terminvolved in this embodiment is the same as or similar to the foregoingterm. The electronic device includes a first image shooting unit 401 anda second image shooting unit 402 configured to respectively collect, ata same moment, a first image and a second image of a first object, afirst actuator 403, and a processor 404 configured to calculate M piecesof first depth information of M same feature point pairs incorresponding areas in the first image and the second image, where M isa positive integer, determine whether confidence of the M pieces offirst depth information is greater than a threshold, obtain focusingdepth information according to N pieces of first depth information inthe M pieces of first depth information when the confidence of the Mpieces of first depth information is greater than the threshold, where Nis a positive integer less than or equal to M, obtain a target positionof a first lens of the first image shooting unit 401 according to thefocusing depth information, and control the first actuator 403 to movesuch that the first lens moves to the target position.

Further, the first image shooting unit 401 includes the first lens and afirst image sensor. The first image sensor is, for example, a CCD or aCMOS. The second image shooting unit 402 includes a second lens and asecond image sensor.

Optionally, the first actuator 403 is a VCM.

Optionally, the corresponding areas correspond to positions of focuswindows when the first image and the second image are collected, anarea, in the first image is a first area, an area in the second image isa second area, and the processor 404 is further configured to determinewhether a quantity of first feature points in the first area is greaterthan or equal to a first threshold or determine whether a quantity ofsecond feature points in the second area is greater than or equal to asecond threshold, and determine that the confidence of the M pieces offirst depth information is less than or equal to the threshold when thequantity of first feature points is less than the first threshold and/orthe quantity of second feature points is less than the second threshold.

The processor 404 is further configured to search, for the first featurepoints, the second feature points in a first sequence for first matchingfeature points that match the first feature points, and search thesecond feature points in a second sequence for second matching featurepoints that match the first feature points when the quantity of firstfeature points is greater than or equal to the first threshold and thequantity of second feature points is greater than or equal to the secondthreshold, where the second sequence is reverse to the first sequence,determine a quantity of same matching feature points in the firstmatching feature points and the second matching feature points andcorresponding to a same feature point in the first feature points, anddetermine that the confidence of the M pieces of first depth informationis less than or equal to the threshold when a proportion of the quantityto the quantity of first feature points is less than a third threshold,or determine that the confidence of the M pieces of first depthinformation is greater than the threshold when a proportion of thequantity to the quantity of first feature points is greater than orequal to a third threshold.

The processor 404 is further configured to obtain the focusing depthinformation according to depth information corresponding to the samefeature point.

With reference to the foregoing embodiments, the electronic devicefurther includes a second actuator 405, and the processor 404 is furtherconfigured to control the second actuator 405 to move in order to movethe second lens of the second image shooting unit 402 to a thirdposition after controlling the first lens to move to the targetposition, determine that a check on the focusing depth informationsucceeds when a first contrast of an image obtained before the firstlens moves to the target position and in a focus window area is lessthan a second contrast of an image obtained when the first lens is atthe target position and in a focus window area, and a third contrast ofan image obtained when the second lens is at the third position and in afocus window area is less than the second contrast, and controlperforming image shooting at the target position.

Optionally, the second actuator 405 may be the same as or may bedifferent from the first actuator 403.

With reference to the foregoing embodiments, the processor 404 isfurther configured to determine that a check on the focusing depthinformation is successful before controlling the first lens to move tothe target position.

The processor 404 is further configured to estimate an estimateddistance between a human face and the first lens according to a size ofa human face frame when the human face is detected in the focus window,and determine that the check on the focusing depth information issuccessful when an absolute value of a difference between the estimateddistance and the focusing depth information is less than or equal to afourth threshold.

With reference to the foregoing embodiments, the processor 404 isfurther configured to control the first lens and the second lens of thesecond image shooting unit 402 to move to new positions when theconfidence of the M pieces of first depth information is less than orequal to the threshold or the check fails, and at the new positions, athird image and a fourth image of the first object and collected at asame time using the first image shooting unit 401 and the second imageshooting unit 402.

The processor 404 is further configured to calculate P pieces of seconddepth information of N same feature point pairs in corresponding areasin the third image and the fourth image, where P is a positive integer,determine whether confidence of the P pieces of second depth informationis greater than the threshold, obtain new focusing depth informationaccording to L pieces of second depth information in the P pieces ofsecond depth information when the confidence of the P pieces of seconddepth information is greater than the threshold, where L is a positiveinteger less than or equal to P, obtain a new target position of thefirst lens according to the new focusing depth information, and controlthe first lens to move to the new target position.

With reference to the foregoing embodiments, the processor 404 isfurther configured to control a second lens of the second image shootingunit 402 to move to a position corresponding to the target position whencontrolling the first lens to move to the target position.

Continuing to refer to FIG. 5, the electronic device further includes adisplay 406 configured to display an image/images obtained by the firstimage shooting unit 401 and/or the second image shooting unit 402 or theprocessor 404.

Optionally, the electronic device further includes a memory 407configured to store data that is used when the processor 404 performs anoperation or temporary image data obtained by the first image shootingunit 401 and/or the second image shooting unit 402.

Optionally, the processor 404 may further include a central processingunit (CPU) and an ISP.

Optionally, the processor 404 is a CPU and is a chip that is mutuallyindependent of an ISP physically.

Optionally, the electronic device further includes a battery configuredto supply power to the electronic device.

Various types of variations and specific examples in the auto-focusmethod in the foregoing embodiments in FIG. 1 to FIG. 3 are alsoapplicable to the electronic device in this embodiment. With thedetailed description of the foregoing auto-focus method, persons skilledin the art may clearly understand an implementation method of theelectronic device in this embodiment. Therefore, for conciseness of thespecification, details are not described herein again.

One or more technical solutions provided in the embodiments of thisapplication have at least the following technical effects or advantages.

In the embodiments of this application, at a same moment, a first imageof a first object is collected using a first image shooting unit, and asecond image of the first object is collected using a second imageshooting unit, M pieces of first depth information of M same featurepoint pairs in corresponding areas in the first image and the secondimage are calculated, it is determined whether confidence of the Mpieces of first depth information is greater than a threshold. A targetposition of a first lens is calculated according to the M pieces offirst depth information, and the first lens is controlled to move to thetarget position when the confidence of the M pieces of first depthinformation is greater than the threshold. Therefore, in theembodiments, confidence of an object distance obtained in activefocusing, that is, the M pieces of first depth information isdetermined. An active focusing method is used only when the confidenceis greater than the threshold, that is, the target position of the firstlens is obtained according to N pieces of first depth information in theM pieces of first depth information, and then the first lens iscontrolled to move to a current position to complete focusing.Therefore, in comparison with an active focusing method in otherapproaches, focusing precision is improved.

Persons skilled in the art should understand that the embodiments ofthis application may be provided as method and device embodiments andmay be implemented in a hardware or combination of software and hardwaremanner.

This application is described with reference to the flowcharts or blockdiagrams of the method, the device (system), and the computer programproduct according to the embodiments of this application. It should beunderstood that computer program instructions may be used to implementeach process or each block in the flowcharts or the block diagrams and acombination of a process or a block in the flowcharts or the blockdiagrams. These computer program instructions may be provided for ageneral-purpose computer, a dedicated computer, an embedded processor,or a processor of any other programmable data processing device togenerate a machine such that the instructions executed by a computer ora processor of any other programmable data processing device generate anapparatus for implementing a specific function in one or more processesin the flowcharts or in one or more blocks in the block diagrams.

These computer program instructions may be stored in a computer-readablememory that can instruct the computer or any other programmable dataprocessing device such that the instructions stored in thecomputer-readable memory generate an artifact that includes aninstruction apparatus. The instruction apparatus implements a specificfunction in one or more processes in the flowcharts or in one or moreblocks in the block diagrams.

These computer program instructions may also be loaded onto a computeror another programmable data processing device such that a series ofoperations and steps are performed on the computer or the otherprogrammable device, thereby generating computer-implemented processing.Therefore, the instructions executed on the computer or the otherprogrammable device provide steps for implementing a specific functionin one or more processes in the flowcharts or in one or more blocks inthe block diagrams.

Obviously, persons skilled in the art can make various modifications andvariations to this application without departing from the spirit andscope of this application. This application is intended to cover thesemodifications and variations provided that they fall within the scope ofprotection defined by the following claims and their equivalenttechnologies.

What is claimed is:
 1. An auto-focus method, comprising: collecting afirst image of a first object using a first camera; collecting a secondimage of the first object using a second camera; obtaining focusingdepth information of the first image and the second image; obtaining atarget position of a first lens of the first camera according to thefocusing depth information; and controlling the first lens to move tothe target position.
 2. The method according to claim 1, furthercomprising controlling a second lens of the second camera to move to thetarget position.
 3. The method according to claim 1, further comprisingshooting an image in response to a user operation.
 4. The methodaccording to claim 1, wherein an optical axis of the first camera isparallel to an optical axis of the second camera.
 5. The methodaccording to claim 1, wherein the first object is a face.
 6. Anelectronic device, comprising: a first camera having a first lens; asecond camera having a second lens, the first camera and the secondcamera being disposed on a same plane of the electronic device; a firstactuator; and a processor coupled to the first camera, the secondcamera, and the first actuator, the processor configured to controlmovement of the first lens by controlling a the first actuator.
 7. Theelectronic device according to claim 6, wherein the first camera and thesecond camera are disposed on a rear cover of the electronic device. 8.The electronic device according to claim 6, wherein the processor isconfigured to control movement of the second lens.
 9. The electronicdevice according to claim 6, wherein a parameter of the first camera isthe same as a parameter of the second camera.
 10. The electronic deviceaccording to claim 9, wherein the first camera and the second camerahave a same focal length.
 11. The electronic device according to claim6, wherein an optical axis of the first camera is parallel to an opticalaxis of the second camera.
 12. The electronic device according to claim6, wherein the first actuator is a voice coil motor (VCM).
 13. Theelectronic device according to claim 7, wherein the voice coil motor(VCM) comprises: a magnet set; and a coil fixed in the magnet set usingtwo spring plates, the coil configured to generate a magnetic field whenthe coil is powered on, the magnetic field interacting with the magnetset to move the coil upward, the first lens being locked in the coilsuch that the coil and the first lens move together, and the coilconfigured to return back to an original position under an elastic forceof the spring plate when the coil is powered off.
 14. The electronicdevice according to claim 6, wherein the electronic device is a mobilephone.